package cn.zucc.edu.bruce.iot.receiver;

import cn.zucc.edu.bruce.iot.DataDeal;

public class ReceiveMotorData extends ReceiveSensorData {
    private long speed;

    public ReceiveMotorData(byte[] bytes) {
        setSensorNumber(3);
        this.speed = getUnsigned(DataDeal.bytesToInt(bytes, 0));
    }

    public ReceiveMotorData(long speed) {
        this.speed = speed;
    }

    public long getSpeed() {
        return speed;
    }

    public void setSpeed(long speed) {
        this.speed = speed;
    }

    @Override
    public String toString() {
        return super.toString() + " Motor speed: " + this.getSpeed();
    }

    static long getUnsigned(int data) {
        return data > 0 ? data : data & 0x7fffffff + 2147483648L;
    }

}
